package servlet.user;

import model.UserModel;
import net.sf.json.JSONArray;
import service.IUserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/userAdd")
public class UserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        String username=req.getParameter("username");
        String password=req.getParameter("password");

        UserModel user= new UserModel();
        //因为id在数据库是自动增长所以不用赋值
        user.setUsername(username);
        user.setPassword(password);

        IUserService service = new UserServiceImpl();
        int num = service.add(user);

        JSONArray jsonArray=JSONArray.fromObject(num);
        resp.getWriter().println(jsonArray);
    }
}
